package com.gyg.controller;


import com.gyg.returns.RespEntity;
import com.gyg.service.CloudVideoService;
import com.gyg.vo.param.DownloadParam;
import com.gyg.vo.param.FileParam;
import com.gyg.vo.param.UpdateFileParam;
import com.gyg.vo.result.AudioListResult;
import com.gyg.vo.result.CloudInfoResult;
import com.gyg.vo.result.FileDownloadResult;
import com.gyg.vo.result.VideoListResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 视频信息表 前端控制器
 * </p>
 *
 * @author gyg
 * @since 2021-04-14
 */
@RestController
@RequestMapping("/cloud-video")
@Api(value = "视频模块", tags = "视频模块")
@Slf4j
public class CloudVideoController {

    @Resource
    private CloudVideoService cloudVideoService;

    @PostMapping("/upload")
    @ApiOperation(value = "视频上传")
    public RespEntity uploadVideo(@RequestBody FileParam fileParam) {
        RespEntity respEntity = cloudVideoService.uploadVideo(fileParam);
        return respEntity;
    }

    @ApiOperation(value = "视频列表")
    @GetMapping("/list")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "userId", value = "用户id", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "pageNum", value = "当前页数", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "pageSize", value = "每页数量", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "content", value = "搜索内容", required = false)
    })
    public RespEntity<VideoListResult> cloudVideoList(@RequestParam(value = "userId", required = true) Integer userId,
                                                      @RequestParam(value = "pageNum", required = true) Integer pageNum,
                                                      @RequestParam(value = "pageSize", required = true) Integer pageSize,
                                                      @RequestParam(value = "content", required = false) String content) {
        RespEntity<VideoListResult> respEntity = cloudVideoService.cloudVideoList(userId, pageNum, pageSize, content);
        return respEntity;
    }

    @ApiOperation(value = "编辑视频")
    @PutMapping("/update")
    public RespEntity editVideo(@RequestBody UpdateFileParam updateFileParam) {
        RespEntity respEntity = cloudVideoService.editVideo(updateFileParam);
        return respEntity;
    }

    @ApiOperation(value = "删除视频")
    @DeleteMapping("/delete")
    @ApiImplicitParam(paramType = "delete", dataType = "Integer", name = "videoId", value = "视频id", required = true)
    public RespEntity deleteAudio(@RequestParam(value = "videoId", required = true) Integer videoId) {
        RespEntity respEntity = cloudVideoService.deleteVideo(videoId);
        return respEntity;
    }

    @ApiOperation(value = "视频云盘信息")
    @GetMapping("/info")
    @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "userId", value = "用户id", required = true)
    public RespEntity<CloudInfoResult> videoCloudInfo(@RequestParam(value = "userId", required = true) Integer userId) {
        RespEntity<CloudInfoResult> respEntity = cloudVideoService.videoCloudInfo(userId);
        return respEntity;
    }

    @PostMapping("/download")
    @ApiOperation(value = "视频下载")
    public RespEntity<FileDownloadResult> download(@RequestBody DownloadParam downloadParam) {
        RespEntity<FileDownloadResult> respEntity = cloudVideoService.download(downloadParam);
        return respEntity;
    }

}
